import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:leader_doctor_flutter/common/utils/custom_alert_dialog.dart';
import 'package:leader_doctor_flutter/common/utils/string_utils.dart';
import 'package:leader_doctor_flutter/plugins/plugins_messages.g.dart';
import 'package:leader_doctor_flutter/styles/colors.dart';
import 'package:netease_meeting_ui/meeting_ui.dart';

/// @Author lixiaobin
/// @Date 2023/12/22
/// @Description
class UserUtils {
  /// 1 审核已通过 2 资料审核未通过 3 未认证 4 资料审核中
  static bool isAuth(UserInfo? info) {
    return '1' == info?.status;
  }

  /// 用户认证消息弹窗
  static void showAuthDialog(BuildContext context, UserInfo? info) {
    if (info == null) {
      return;
    }
    if ('4' == info.status) {
      ToastUtils.showToast(context, '资料审核中,请耐心等候...');
      return;
    }

    showDialog(
        context: context,
        builder: (BuildContext context) {
          return CustomAlertDialog(
            title: '温馨提示',
            description: authText(info),
            confirmText: const Text(
              '上传资料',
              style: TextStyle(color: ColorRes.colorMain, fontSize: 16),
            ),
            cancelText: const Text(
              '继续体验',
              style: TextStyle(color: ColorRes.colorMain, fontSize: 16),
            ),
            onConfirm: () {
              if ('2' == info.status) {
                NativeInterface().openNativePage('auth_status', '');
              } else if ('3' == info.status) {
                NativeInterface().openNativePage('auth_page', '');
              }
            },
          );
        });
  }

  static String authText(UserInfo? info) {
    if (isAuth(info)) {
      return "审核已通过";
    }
    if (info != null) {
      if ("2" == info.status) {
        return "资料审核未通过，请重新认证";
      }
      if ("3" == info.status) {
        return "您还未认证，请先去认证资料";
      }
      if ("4" == info.status) {
        return "资料审核中";
      }
    }
    return "审核未通过";
  }

  ///     获取年龄性别
  ///     例： 男 | 20岁
  static String getSexAndAge(String? sex, String? age) {
    var sb = '';
    var sexStr = getSex(sex);
    if (StringUtils.isNotEmpty(sexStr)) {
      sb += sexStr;
    }
    var ageStr = getAge(age);
    if (StringUtils.isNotEmpty(ageStr)) {
      sb += ' | ';
      sb += ageStr;
    }
    var str = sb.toString();
    return StringUtils.isNotEmpty(str) ? str : '';
  }

  static String getAge(String? age) {
    return "${age ?? "0"}岁";
  }

  static String getSex(String? sex) {
    return ('0' == sex || '女' == sex)
        ? '女'
        : (('1' == sex || '男' == sex) ? '男' : '未知');
  }
}
